var util =
		{
			fixHtmlEditor: function()
				{
					var field = new Ext.form.Field();
					Ext.override(Ext.form.HtmlEditor,
						{
							markInvalid: field.markInvalid,
							clearInvalid: field.clearInvalid
						});
				},
			
			removeField : function(field)
				{
					if(field && field.el)
					{
						field.el.up('.x-form-item').remove();
						this.remove(field);
						this.doLayout();
					}
				},
			
			createComplementoField : function(params)
				{
					var object = 
						{
							dir : new Ext.form.Hidden
							    ({
							        name: 'data[Complementos]'+params.basename.field+'[dir]'
							    }),
							foreign_key :
								{
									name: new Ext.form.Hidden
									    ({
									        name: 'data[Complementos]'+params.basename.field+'[foreign_key][name]'
									    }),
									value: new Ext.form.Hidden
									    ({
									        name: 'data[Complementos]'+params.basename.field+'[foreign_key][value]'
									    })
								},
							id : new Ext.form.Hidden
							    ({
							        name: 'data[Complementos]'+params.basename.field+'[id]'
							    }),
							tipo_id : new Ext.form.Hidden
							    ({
							        name: 'data[Complementos]'+params.basename.field+'[tipo_id]'
							    }),
							text : new Ext.form.TextArea
							    ({
							        fieldLabel: params.title.text,
							        name: 'data[Complementos]'+params.basename.field+'[texto]',
							        width: params.width,
							        allowBlank: params.allowBlank.text,
							        height: 80
							    }),
							file : new Ext.form.MiscField
							    ({
							        fieldLabel: params.title.file,
							        width: params.width,
							        value: '<input type="file" name="data[Files]['+params.basename.file+'_file]"><span id="'+params.id+'_anexo_ctrl" style="display: none;">&nbsp;<img src="'+_PHP_.url.imgroot+'cross.png" alt="" style="cursor: pointer;" onclick="anexo.del(\''+params.id+'\', row.'+params.id+'.file.url.del)">&nbsp;<img src="'+_PHP_.url.imgroot+'disk.png" alt="" style="cursor: pointer;" onclick="anexo.get(\''+params.id+'\', row.'+params.id+'.file.url.get)"></span><iframe id="'+params.id+'_anexo_dl" style="display: none;"></iframe>',
							        toggleCtrl: function()
							        	{
							        		//alert(params.id);
							        		var ctrl = document.getElementById(params.id+'_anexo_ctrl');
							        		
							        		if(ctrl.style.display == 'none')
							        		{
							        			ctrl.style.display = 'inline';
							        		}
							        		else
							        		{
							        			ctrl.style.display = 'none';
							        		}
							        	},
							        url: 
							        	{
							        		get: null,
							        		del: null
							        	}
							    })
						};
						
					for(var field in params.values)
					{
						eval('object.'+field).setValue(params.values[field]);
					}
					
					return object;
				},
		    
		    iframe : 
				{
			    	create: function(title, id, url, height, collapsed)
					    	{
						    	var fieldset = new Ext.form.FieldSet(
							        {
								        id: id+'_fieldset',
								        title: title,
						                layout: 'form',
						                height: height.lista,
						                collapsible: true,
						                collapsed: collapsed,
								       	tbar: 
									    	[
												new Ext.Button
													({
												        text: 'Listar',
												        icon: _PHP_.url.imgroot+'application_cascade.png',
												        cls: 'x-btn-text-icon',
												        handler: function()
												        	{
												        		util.iframe.changeSRC(id, url.lista, height.lista);
												        	}
												    }),
												new Ext.Button
													({
												        text: 'Adicionar',
												        icon: _PHP_.url.imgroot+'application_add.png',
												        cls: 'x-btn-text-icon',
												        handler: function()
												        	{
												        		util.iframe.changeSRC(id, url.add, height.add);
												        	}
												    })
											]
								    });
								    
								 var panel = new Ext.Panel(
									{
										html: '<iframe id="'+id+'_iframe" allowtransparency="yes" frameborder="0" style="boder: 0; width: 100%; height: '+util.iframe.calculateHeight(height.lista)+'px;" src="'+(url.start ? url.start : url.lista)+'"></iframe>'
					            	}); 
					            					 
								 if(collapsed)
								 {
									 fieldset.on('collapse', function()
										{
											fieldset.add(panel);
										});
								 }
								 else
								 {
								 	fieldset.add(panel);
								 }
								 
								 return fieldset;
							},
							
					changeSRC: function(id, url, height)
						{
							document.getElementById(id+'_iframe').style.visibility = 'hidden';
							document.getElementById(id+'_iframe').src = url;
							
							setTimeout(function()
								{
									Ext.getCmp(id+'_fieldset').setHeight(height);
									document.getElementById(id+'_iframe').style.height = util.iframe.calculateHeight(height)+'px';
									document.getElementById(id+'_iframe').style.visibility = 'visible';								
								}, 500);
						},
						
					calculateHeight: function(heigth)
						{
							return (84 * heigth)/100;
						}
				}
		};